n=int(input())
nums=list(map(int,input().split()))

a=[nums[0]]
for i in range(1,n):
    if nums[i]==a[-1]:
        continue
    a.append(nums[i])

a.insert(0,0);
a.append(0)

n=len(a)

count=[0 for i in range(0,10001)]

for i in range(1,n-1):
    if a[i]>a[i-1] and a[i]>a[i+1]:
        count[a[i]]+=1
    elif a[i]<a[i-1] and a[i]<a[i+1]:
        count[a[i]]-=1

s=0
r=0
for i in range(10000,0,-1):
    s+=count[i]
    r=max(r,s)

print(r)
